package com.xishu.service;

import com.xishu.entity.order.OrderItem;
import com.xishu.entity.shop.ItemDetail;
import com.xishu.entity.shop.NameAndPrice;
import com.xishu.entity.shop.Shop;
import com.xishu.util.Tools;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static com.xishu.config.Constant.*;

public class LangService implements Tools {
    private static LangService instance = new LangService();

    private LangService() {
    }

    public static LangService getInstance() {
        return instance;
    }

    /**
     * 获取分店的名称
     *
     * @param zh
     */
    public String getShopName(Shop shop, boolean zh) {
        if (zh) {
            return shop.getName_zh();
        } else {
            return shop.getName_en();
        }
    }

    /**
     * 详情地址
     *
     * @param shop
     * @param zh
     * @return
     */
    public String getShopDetailAddress(Shop shop, boolean zh) {
        if (zh) {
            return getString(shop.getShopDetailAddress_zh());
        } else {
            return getString(shop.getShopDetailAddress_en());
        }
    }

    public String getItemDetailName(ItemDetail itemDetail, boolean zh) {
        if (zh) {
            return getString(itemDetail.getName_zh());
        } else {
            return getString(itemDetail.getName_en());
        }
    }

    public String getNameAndPriceName(NameAndPrice nameAndPrice, boolean zh) {
        if (zh) {
            return getString(nameAndPrice.getName_zh());
        } else {
            return getString(nameAndPrice.getName_en());
        }
    }

    public String getOrderItemName(OrderItem orderItem, boolean zh) {
        if (zh) {
            return StringUtils.stripEnd(getString(orderItem.getItemName_zh()),null);
        } else {
            return StringUtils.stripEnd(getString(orderItem.getItemName_en()),null);
        }
    }

    public String getDetailName(ItemDetail itemDetail, boolean zh) {
        if (zh) {
            return getString(itemDetail.getName_zh());
        } else {
            return getString(itemDetail.getName_en());
        }
    }

    /**
     * 获取商店的地址信息
     *
     * @param shop
     * @param zh
     */
    public String getShopAddress(Shop shop, boolean zh) {
        ShopService.getInstance().formatShopAddress(shop);
        if (zh) {
            String addressShow = getString(shop.getShowAddressShow_zh());
            return addressShow + " " + getShopDetailAddress(shop, zh);
        } else {
            return getShopDetailAddress(shop, zh);
        }
    }

    /**
     * 获取支付方式的显示
     *
     * @param payType
     * @param zh
     * @return
     */
    public String getPayType(Long payType, boolean zh) {
        if (zh) {
            Map<Long, String> map = new HashMap<>();
            map.put(Long.valueOf(ORDER_PAY_TYPE_WEIXIN), "微信");
            map.put(Long.valueOf(ORDER_PAY_TYPE_ALIPAY), "支付寶");
            map.put(Long.valueOf(ORDER_PAY_TYPE_MASTER), "Mastercard");
            map.put(Long.valueOf(ORDER_PAY_TYPE_VISA), "Visa");
            map.put(Long.valueOf(ORDER_PAY_TYPE_CASH), "現金");
            map.put(Long.valueOf(ORDER_PAY_TYPE_APPLE), "Apply Pay");
            map.put(Long.valueOf(ORDER_PAY_TYPE_GOOGLE), "Google Pay");
            map.put(Long.valueOf(ORDER_PAY_TYPE_BA_DA_TONG), "八達通");
            map.put(Long.valueOf(ORDER_PAY_TYPE_UNION_PAY), "銀聯");
            map.put(Long.valueOf(ORDER_PAY_TYPE_AMERICAN_EXPRESS), "American Express");
            map.put(Long.valueOf(ORDER_PAY_TYPE_STRIPE), "Stripe");
            map.put(Long.valueOf(ORDER_PAY_TYPE_CREDIT_CARD), "信用卡");
            map.put(Long.valueOf(ORDER_PAY_TYPE_CHEQUE), "支票");
            return map.get(payType);
        } else {
            HashMap<Long, String> map = new HashMap<>();
            map.put(Long.valueOf(ORDER_PAY_TYPE_WEIXIN), "Wechat");
            map.put(Long.valueOf(ORDER_PAY_TYPE_ALIPAY), "Alipay");
            map.put(Long.valueOf(ORDER_PAY_TYPE_MASTER), "Mastercard");
            map.put(Long.valueOf(ORDER_PAY_TYPE_VISA), "Visa");
            map.put(Long.valueOf(ORDER_PAY_TYPE_CASH), "Cash");
            map.put(Long.valueOf(ORDER_PAY_TYPE_APPLE), "Apply Pay");
            map.put(Long.valueOf(ORDER_PAY_TYPE_GOOGLE), "Google Pay");
            map.put(Long.valueOf(ORDER_PAY_TYPE_BA_DA_TONG), "Octopus");
            map.put(Long.valueOf(ORDER_PAY_TYPE_UNION_PAY), "UnionPay");
            map.put(Long.valueOf(ORDER_PAY_TYPE_AMERICAN_EXPRESS), "American Express");
            map.put(Long.valueOf(ORDER_PAY_TYPE_STRIPE), "Stripe");
            map.put(Long.valueOf(ORDER_PAY_TYPE_CREDIT_CARD), "Credit Card");
            map.put(Long.valueOf(ORDER_PAY_TYPE_CHEQUE), "Cheque");
            return map.get(payType);
        }
    }


}
